package de.slothsoft.commons.swing.util;

import java.awt.Font;

import javax.swing.JEditorPane;
import javax.swing.UIManager;
import javax.swing.text.html.HTMLDocument;

import de.slothsoft.commons.swing.CodeEditorKit;

public class JEditorPaneUtil {

	/**
	 * Creates an JEditorPane for html, using the system font as a default
	 * (instead of "Times New Roman"). The editor will not be editable
	 * 
	 * @return JEditorPane
	 */

	@SuppressWarnings("nls")
	public static JEditorPane createHtmlEditorPane() {
		JEditorPane editor = new JEditorPane("text/html", null);
		editor.setEditable(false);

		Font font = UIManager.getFont("Label.font");
		String bodyRule = "body { font-family: " + font.getFamily() + "; "
				+ "font-size: " + font.getSize() + "pt; }";
		((HTMLDocument) editor.getDocument()).getStyleSheet().addRule(bodyRule);

		return editor;
	}

	/**
	 * Creates an JEditorPane for rtf with no wrapping whatsoever and smaller
	 * tabs than on default.
	 * 
	 * @return JEditorPane
	 */

	@SuppressWarnings("nls")
	public static JEditorPane createRtfCodeEditorPane() {
		JEditorPane editor = new JEditorPane("text/rtf", null);
		editor.setEditable(false);
		editor.setEditorKit(new CodeEditorKit());
		return editor;
	}

}
